<template>
  <div>
    <!-- 头部 -->
    <div class="header">
      <div class="title">
        <span>候选人管理</span>
        <div>管理所有候选人信息和面试安排</div>
      </div>
      <el-button type="primary" @click="addUser"><el-icon>
          <Plus />
        </el-icon>添加候选人</el-button>
    </div>
    <!-- search -->
    <div>
      <el-row :span="24" class="search">
        <el-col :span="5">
          <span>状态</span>
          <div>
            <el-select v-model="value" placeholder="全部" style="width: 200px">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </div>
        </el-col>
        <el-col :span="5">
          <span>职位</span>
          <div>
            <el-select v-model="value" placeholder="全部职位" style="width: 200px">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </div>
        </el-col>
        <el-col :span="8">
          <span>日期范围</span>
          <div class="block" style="display: flex;">
            <el-date-picker v-model="value1" type="date" placeholder="Pick a day" :size="size" />
            <span>至</span>
            <el-date-picker v-model="value1" type="date" placeholder="Pick a day" :size="size" />
          </div>
        </el-col>
        <el-col :span="4" style="margin-left: 40px;">
          <el-input v-model="input2" style="width: 240px" placeholder="搜索候选人..." :suffix-icon="Search" />
        </el-col>
      </el-row>
    </div>
    <!-- Content -->
    <div class="table">
      <el-table ref="multipleTableRef" :data="tableData" row-key="id" style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column type="selection" :selectable="selectable" width="55" />
        <el-table-column property="name" label="候选人" width="120" />
        <el-table-column property="name" label="联系方式" width="220" />
        <el-table-column property="address" label="应聘职位" width="150" />
        <el-table-column label="Date" width="120">
          <template #default="scope">{{ scope.row.date }}</template>
        </el-table-column>
        <el-table-column property="name" label="面试状态" width="150" />
        <el-table-column property="name" label="面试结果" width="120" />

        <el-table-column label="操作">
          <template #default="scope">{{ scope.row.date }}</template>
        </el-table-column>
      </el-table>
    </div>


    <!-- 添加候选人弹窗 -->
    <el-dialog v-model="dialogVisible" title="添加候选人" width="750" :before-close="handleClose">
      <div class="dialog-content">
        <el-form :model="form" label-width="auto" style="max-width: 750px">
          <el-form-item>
            <div class="label">
              <span>姓名</span>
              <span class="required">*</span>
            </div>
            <el-input v-model="form.name" />
          </el-form-item>
          <el-form-item>
            <div class="label">
              <span>性别</span>
            </div>
            <el-select v-model="form.sex" placeholder="请选择性别" style="width: 750px">
              <el-option v-for="item in sexOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <div class="label">
              <span>邮箱</span>
              <span class="required">*</span>
            </div>
            <el-input v-model="form.email" />
          </el-form-item>
          <el-form-item>
            <div class="label">
              <span>电话号码</span>
              <span class="required">*</span>
            </div>
            <el-input v-model="form.tel" />
          </el-form-item>
          <el-form-item>
            <div class="label">
              <span>应聘职位</span>
              <span class="required">*</span>
            </div>
            <el-select v-model="form.work" placeholder="请选择应聘职位" style="width: 750px">
              <el-option v-for="item in workOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <div class="label">
              <span>工作经验（年）</span>
            </div>
            <el-input v-model="form.year" />
          </el-form-item>
          <el-form-item>
            <div class="label">
              <span>最高学历</span>

            </div>
            <el-select v-model="form.study" placeholder="请选择" style="width: 750px">
              <el-option v-for="item in educationOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <div class="label">
              <span>毕业院校</span>

            </div>
            <el-input v-model="form.studySchool" />
          </el-form-item>
          <el-form-item>
            <div class="label">
              <span>技能标签</span>
              <div>
                <span v-for="item in skillarr" :key="item.indexOf" class="tag">{{ item }}</span>
              </div>
            </div>
            <el-input v-model="form.skill" @keydown.enter="addSkill" placeholder="按下Enter键添加技能标签" />
          </el-form-item>
          <el-form-item>
            <div class="label">
              <span>上传简历</span>
            </div>
            <br>
            <div style="width: 100%;">
              <el-upload class="upload-demo" drag multiple>
                <el-icon class="el-icon--upload"><upload-filled /></el-icon>
                <div class="el-upload__text">
                  拖放文件到这里或 <em>点击上传</em>
                </div>
                <template #tip>
                  <div class="el-upload__tip">
                    允许上传的文件类型: PDF, DOC, DOCX，最大文件大小: 10MB
                  </div>
                </template>
              </el-upload>
            </div>

          </el-form-item>
          <el-form-item>
            <div class="label">
              <span>备注</span>
            </div>
            <textarea style="width: 100%;height: 50px;"></textarea>
          </el-form-item>
          <el-form-item class="dialog-footer">
            <el-button @click="dialogVisible = false">取消</el-button>
            <el-button type="primary" @click="addUserReady">
              添加
            </el-button>
          </el-form-item>
        </el-form>
      </div>

    </el-dialog>
  </div>
</template>

<script setup lang="ts">
// 引入api
import { getCandiDateList } from '@/api/getCandiDate'
import { Search } from '@element-plus/icons-vue'
import { ElMessageBox } from 'element-plus'
import { onMounted } from 'vue'
import { ref } from 'vue'
const dialogVisible = ref(false)
const form = ref({
  name: '',
  sex: "",
  email: '',
  tel: '',
  work: '',
  year: '',
  studySchool: '',
  study: "",
  skill: ''
})

const getData = async () => {
  console.log(1111)
  const res = await getCandiDateList()
  console.log('候选人列表', res)
}
const skillarr = ref<string[]>([])
const addSkill = () => {
  if (form.value.skill.trim()) {
    skillarr.value.push(form.value.skill)
    form.value.skill = '' // 清空输入框
  }
}
interface User {
  id: number
  date: string
  name: string
  address: string
}
const tableData: User[] = [
  {
    id: 1,
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: 2,
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: 3,
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: 4,
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: 5,
    date: '2016-05-08',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  }
]

// 添加候选人按钮
const addUser = () => {
  dialogVisible.value = true
}
// 确认添加候选人
const addUserReady = () => {
  dialogVisible.value = false

}

// 性别数据
const sexOptions = [
  {
    value: '男',
    label: '男',
  },
  {
    value: '女',
    label: '女',
  },
]
// 职位数据
const workOptions = [
  {
    value: '前端开发工程师',
    label: '前端开发工程师',
  },
  {
    value: '后端开发工程师',
    label: '后端开发工程师',
  },
  {
    value: '全栈开发工程师',
    label: '全栈开发工程师',
  },
  {
    value: '测试工程师',
    label: '测试工程师',
  },
  {
    value: '运维工程师',
    label: '运维工程师',
  },
  {
    value: '项目经理',
    label: '项目经理',
  },
  {
    value: '产品经理',
    label: '产品经理',
  },
  {
    value: 'UI设计师',
    label: 'UI设计师',
  },
  {
    value: 'UX设计师',
    label: 'UX设计师',
  },
  {
    value: 'DevOps工程师',
    label: 'DevOps工程师',
  },
]
// 学历数据
const educationOptions = [
  {
    value: '高中',
    label: '高中',
  },
  {
    value: '大专',
    label: '大专',
  },
  {
    value: '本科',
    label: '本科',
  },
  {
    value: '硕士',
    label: '硕士',
  },
  {
    value: '博士',
    label: '博士',
  },
]
const handleClose = (done: () => void) => {
  ElMessageBox.confirm('确认关闭添加候选人吗')
    .then(() => {
      done()
    })
    .catch(() => {
      // catch error
    })
}


// 定义 selectable 方法
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const selectable = (row: User, index: number) => {
  return true // 根据需求决定是否可选
}

// 定义 handleSelectionChange 方法
const handleSelectionChange = (selection: User[]) => {
  console.log('Selected Rows:', selection)
  // 在这里处理选中的行数据
}
onMounted(() => {
  getData()
})
</script>

<style scoped>
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.title span {
  margin: 0;
  font-size: 24px;
  font-weight: 500;
}

.title div {
  color: #999;
}

.search {
  margin: 30px 0;
  box-sizing: border-box;
  padding-top: 10px;
  padding-left: 20px;
  padding-bottom: 15px;
  width: 100%;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-self: space-between;
}

.search span {
  font-size: 14px;
  color: #000;
}

.table {
  margin-top: 30px;
}

.el-form .label span:first-child {
  font-weight: 500;
  color: #000;
}


.el-form .label .required {
  color: red;
}

/* 添加滚动条样式 */
.dialog-content {
  max-height: 500px;
  /* 设置最大高度 */
  overflow-y: auto;
  /* 启用垂直滚动条 */
}

/* 上传文件 */
/* .el-upload-dragger {
  border: 0;
  padding: 0;
} */

/* 技能标签 */
.tag {
  background-color: pink;
  padding: 5px;
  font-size: 12px;
  border-radius: 15px;

}
</style>
